<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "member_address".
 *
 * @property integer $member_address_id
 * @property integer $member_id
 * @property string $consignee
 * @property string $mobile
 * @property integer $country_id
 * @property integer $province_id
 * @property integer $city_id
 * @property integer $area_id
 * @property string $pca_info
 * @property string $address
 * @property string $zip_code
 * @property string $tel
 * @property string $sign_building
 * @property string $best_time
 * @property integer $is_default
 * @property integer $create_time
 *
 * @property Member $member
 */
class MemberAddress extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'member_address';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['member_id', 'consignee', 'mobile', 'province_id', 'city_id', 'area_id', 'pca_info', 'address', 'create_time'], 'required'],
            [['member_id', 'country_id', 'province_id', 'city_id', 'area_id', 'is_default', 'create_time'], 'integer'],
            [['consignee'], 'string', 'max' => 50],
            [['mobile', 'tel'], 'string', 'max' => 20],
            [['pca_info', 'sign_building', 'best_time'], 'string', 'max' => 100],
            [['address'], 'string', 'max' => 255],
            [['zip_code'], 'string', 'max' => 10],
            [['member_id'], 'exist', 'skipOnError' => true, 'targetClass' => Member::className(), 'targetAttribute' => ['member_id' => 'member_id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'member_address_id' => '地址ID',
            'member_id' => '会员ID',
            'consignee' => '收货人',
            'mobile' => '手机号码',
            'country_id' => '国家',
            'province_id' => '省',
            'city_id' => '市',
            'area_id' => '区',
            'pca_info' => '省市区',
            'address' => '详细地址',
            'zip_code' => '邮编',
            'tel' => '固话',
            'sign_building' => '标志建筑',
            'best_time' => '最佳送货时间',
            'is_default' => '是否默认，添加第一个地址设为默认',
            'create_time' => '创建时间',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getMember()
    {
        return $this->hasOne(Member::className(), ['member_id' => 'member_id']);
    }
}
